{% macro chapter_tree(chapters) %}
    {% if chapters is not empty %}
    <ol class="dd-list">
        {% for chapter in chapters %}
            <li class="dd-item" data-id="{{ chapter['id'] }}">
                <div class="dd-handle">
                    {{ loop.index }}. &nbsp;<strong>{{ chapter['name']|raw }}</strong>
                    {% if chapter['openTime'] %}
                    <span class='font-weight-lighter' style="margin-left: 20px; color: #999">开课时间：{{ chapter['openTime']|date('Y-m-d H:i') }}</span>
                    {% endif %}

                    <span class="pull-right dd-nodrag">
                {% if is_authorized('admin_teach_chapter_add') and (chapter['parentId'] == 0) %}
                    <a href="{{ path("admin_teach_chapter_add", {"id":chapter['courseId']}) }}?pid={{ chapter['id'] }}" data-title="添加子章节"  title="添加子章节" class="poppage"><i class="mdi mdi-plus"></i></a>
                {% endif %}

            {% if is_authorized('admin_teach_chapter_live') and (chapter['childs'] is empty) %}
                    {% if (chapter['studyWay'] == 1) and ((chapter['video'] and chapter['video']['type']==1) or ( chapter['video'] is empty)) %}
                    <a href="{{ path("admin_teach_chapter_live", {"id":chapter['id']}) }}" data-title="管理直播"  title="管理直播" class="poppage" {% if chapter['video'] and chapter['video']['liveData']!="" %} style="color:#75C82A"  {% endif %} ><i class="mdi mdi-video"></i></a>
                    {% endif %}
            {% endif %}
            {% if is_authorized('admin_teach_chapter_liveView') and (chapter['childs'] is empty) %}
                        {% if (chapter['studyWay'] == 1) and ((chapter['video'] and chapter['video']['type']==1 and chapter['video']['liveData']!="" )) %}
                <a  target="_blank" href="{{ path('admin_teach_chapter_liveView', {"id":chapter['id']}) }}" title="进入直播"><i class="mdi mdi-eye"></i></a>
                        {% endif %}
            {% endif %}

                {% if is_authorized('admin_teach_chapter_vod') and (chapter['childs'] is empty)%}
                    {% if (chapter['studyWay'] != 3) %}
            <a href="{{ path("admin_teach_chapter_vod", {"id":chapter['id']}) }}" data-title="管理点播"  title="管理点播" class="poppage"  {% if chapter['video'] and chapter['video']['status']==1 %} style="color:#75C82A"  {% endif %}   ><i class="mdi mdi-library-video"></i></a>
                    {% endif %}
                {% endif %}

                {% if is_authorized('admin_teach_chapter_edit') %}
                    <a href="{{ path("admin_teach_chapter_edit", {"id":chapter['id']}) }}" data-title="编辑"  title="编辑" class="poppage"><i class="mdi mdi-file-document-edit"></i></a>
                {% endif %}

                {% if is_authorized('admin_api_teach_chapter_delete') %}
                    <a href="{{ path("admin_api_teach_chapter_delete", {"id":chapter['id']}) }}" title="删除"  data-confirm="确认要删除吗?" class="tree_branch_delete ajaxDelete"><i class="mdi mdi-delete"></i></a>
                {% endif %}
                </span>
                </div>
                {{ _self.chapter_tree(chapter['childs']) }}
            </li>
        {% endfor %}
    </ol>
    {% endif %}
{% endmacro %}
